/*
 *
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: RequestFactory.java
 *   @Date: 11/29/18 3:21 PM
 *   @Author: chenjun
 *   @Copyright（C）: 2018 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 *
 */

package io.bhex.baselib.network.request;

import java.util.HashMap;
import java.util.Map;

import io.bhex.baselib.network.params.IParams;
import io.bhex.baselib.utils.DebugLog;
import okhttp3.Request;


public class RequestFactory {
    private static Map<String, IRequestBuilder> builderMap = new HashMap<>();

    public static Request createRequest(IParams params) {
        String clazzName = params.getRequestBuilderClazz();
        IRequestBuilder builder = builderMap.get(clazzName);
        if (builder == null) {
            try {
                builder = (IRequestBuilder) Class.forName(clazzName).newInstance();
                builderMap.put(clazzName, builder);
            } catch (Exception e) {
                DebugLog.e(e);
            }
        }
        return builder.params(params).build();
    }
}
